package helper.xls;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */



import jxl.Cell;
import jxl.CellType;
import jxl.format.CellFormat;
import jxl.write.Label;
import jxl.write.WritableCell;
import jxl.write.WritableSheet;
import jxl.write.WriteException;


/**
 *
 * @author Andrzej
 */
public class TemplateHelper {

        public static void addCell(WritableSheet sheet, int x, int y, String value, CellFormat cfs[]) throws WriteException{
            Label l = new Label(x,y, value, cfs[x]);
            sheet.addCell(l);

    }
    public static void addCell(WritableSheet sheet, int x, int y, double value, CellFormat cfs[]) throws WriteException {
        jxl.write.Number n = new jxl.write.Number(x, y, value, cfs[x]);
        sheet.addCell(n);

    }

    public static void setNumber(WritableSheet sheet, int x, int y, double value) {
         WritableCell cell = sheet.getWritableCell(x, y);
        if (cell.getType() == CellType.NUMBER) {
            jxl.write.Number l = (jxl.write.Number) cell;
            l.setValue(value); //tutaj nalezy wstawi� warto�ci zamiast dd.mm.rrrr
        }
        else
         assert(false):"sheet.getWritableCell("+x +","+ y +").getType() != CellType.NUMBER";
    }

    public static void setString(WritableSheet sheet, int x, int y, String value) {
        WritableCell cell = sheet.getWritableCell(x, y);
        if (cell.getType() == CellType.LABEL) {
            Label l = (Label) cell;
            l.setString(value); //tutaj nalezy wstawi� warto�ci zamiast dd.mm.rrrr
        }
        else
            assert(false):"sheet.getWritableCell("+x +","+ y +").getType() != CellType.LABEL";
    }
    public static void copyRow(WritableSheet sheet, int from, int to) throws WriteException {
        sheet.insertRow(to);
        for (Cell cell:sheet.getRow(from)){
            WritableCell copiedCell = sheet.getWritableCell(cell.getColumn(), cell.getRow()).copyTo(cell.getColumn(), to);
            sheet.addCell(copiedCell);
        }
    }

}
